using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Assets.Actions.Base;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateVSService
{
	/// <summary>
	/// Action that adds/update the ProvideService attribute
	/// </summary>
	public class AddProvideServiceAttributeAction : ActionBase
	{
		#region Properties
		private CodeClass codeClass;

		/// <summary>
		/// Gets or sets the code class.
		/// </summary>
		/// <value>The code class.</value>
		[Input(Required = true)]
		public CodeClass CodeClass
		{
			get { return codeClass; }
			set { codeClass = value; }
		}

		private string serviceName;

		/// <summary>
		/// Gets or sets the name of the service.
		/// </summary>
		/// <value>The name of the service.</value>
		[Input(Required = true)]
		public string ServiceName
		{
			get { return serviceName; }
			set { serviceName = value; }
		}

		private string serviceNamespace;

		/// <summary>
		/// Gets or sets the service namespace.
		/// </summary>
		/// <value>The service namespace.</value>
		[Input(Required = true)]
		public string ServiceNamespace
		{
			get { return serviceNamespace; }
			set { serviceNamespace = value; }
		} 
		#endregion

		#region Protected Implementation
		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			string attName = "ProvideService";
			string attValue =
				string.Format(
					CultureInfo.CurrentCulture,
					"typeof({0}.S{1}), ServiceName = \"{2}\"", 
					this.serviceNamespace, 
					this.serviceName,
					this.serviceName);

			FileCodeModelHelper.AddAttribute(codeClass, attName, attValue, false);
		} 
		#endregion
	}
}